<template>
  <div class="page-container">
    <div class="control-container">
      <div class="right-panel">
        <div class="search-panel">
          <el-form :inline="true" label-width="100">
<!--            <el-form-item label="开始时间">-->
<!--              <el-date-picker-->
<!--                v-model="query.startTime"-->
<!--                type="datetime"-->
<!--                placeholder="选择日期"-->
<!--                value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                :clearable="true"-->
<!--              />-->
<!--            </el-form-item>-->
<!--            <el-form-item label="结束时间">-->
<!--              <el-date-picker-->
<!--                v-model="query.endTime"-->
<!--                type="datetime"-->
<!--                placeholder="选择日期"-->
<!--                value-format="yyyy-MM-dd HH:mm:ss"-->
<!--                :clearable="true"-->
<!--              />-->
<!--            </el-form-item>-->
            <el-form-item label="报表类型：">
              <el-select v-model="query.queryType" filterable clearable placeholder="请选择" @change="handleSelect">
                <el-option
                  v-for="(item,index) in queryTypes"
                  :key="'selectQueryType'+index"
                  :label="item.lable"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
            <el-button type="primary" @click="handleSelect">查询</el-button>
          </el-form>
        </div>
        <div class="table-panel">
          <el-table
            v-loading="tableLoading"
            class="grid-data-table"
            height="calc(100vh - 400px)"
            :data="tableData"
          >
            <el-table-column align="center" type="index" width="80" />
            <el-table-column prop="time" label="时间"  >
              <template  slot-scope="scope" >
                <span v-if="query.queryType==='WEEK'" style="margin-left: 10px" >第{{ scope.row.time }}周</span>
                <span v-if="query.queryType==='QUARTER'" style="margin-left: 10px" >第{{ scope.row.time }}季度</span>
                <span v-if="query.queryType==='MONTH'" style="margin-left: 10px" >{{ scope.row.time}}</span>
                <span v-if="query.queryType==='YEAR'" style="margin-left: 10px" >{{ scope.row.time}}</span>
              </template>

            </el-table-column>
            <template v-for="(item,index) in tableHead">
              <el-table-column :key="index" :prop="item" :label="item" min-width="120"  />
            </template>
          </el-table>
          <div class="pagination-container">
            <Pagination
              v-show="query.total>0"
              :total="query.total"
              :page.sync="query.page"
              :limit.sync="query.limit"
              @pagination="initData"
            />
          </div>
        </div>
      </div>
    </div>

  </div>
</template>

<script>
import Pagination from '@/components/Pagination'
import { selectReport } from '@/api/base/statistics'

export default {
  name: 'weekReport',
  components: {
    Pagination,
  },
  data() {
    return {
      tableLoading: false,
      query: {
        page: 1, limit: 10, total: 0,
        queryType:"MONTH",
      },
      tableData: [],
      tableHead: [],
      queryTypes:[{value:"WEEK",lable:"周"},{value:"MONTH",lable:"月"},{value:"QUARTER",lable:"季度"},{value:"YEAR",lable:"年"},],
      obj: null,
      type: ''
    }
  },
  created() {
    this.initData()
  },
  methods: {
    initData() {
      const query = JSON.parse(JSON.stringify(this.query))
      this.tableLoading = true
      selectReport(query).then(result => {
        debugger
        this.tableLoading = false
        this.tableData = result.data.list
        this.tableHead=result.data.column
        this.tableLoading = false
      }).catch(() => {
        this.tableLoading = false
      })
    },
    // 查询
    handleSelect() {
      this.query.page = 1
      this.initData()
    },
    flushPage() {
      this.clearQuery()
      this.initData()
    },
    clearQuery() {
      this.query = {
        page: 1, limit: 10, total: 0,
        resourceName: null, resourceType: null
      }
    }
  }
}
</script>

<style lang="scss" scoped>
.download{
  margin: 0px 8px 4px 8px !important;
}
</style>
